/**
 * indexDB添加数失败错误类
 */
export default class IndexDBQueryError extends Error{
    private readonly dbName: string;
    private readonly tableName: string;
    private readonly queryField: string;
    private readonly queryValue: string | number;
    private readonly errorName: string | undefined ;
    private readonly errorInfo: string | undefined;
    private readonly stack_: string | undefined;
    constructor(dbName: string, tableName: string, queryField: string, queryValue: string | number, originalError: DOMException | null) {
        const msg = originalError ? `\n\tErrorType: ${originalError.name}\n\tErrorInfo: ${originalError.message}\n\tErrorStack: ${originalError.stack}` : ""
        super(`\n\tErrorDatabase: ${dbName}\n\tErrorTable: ${tableName}\n\tErrorField: ${queryField}\n\tErrorValue: ${queryValue}${msg}`);
        this.dbName = dbName;
        this.tableName =tableName;
        this.queryField = queryField;
        this.queryValue = queryValue;
        if (originalError){
            this.errorName = originalError.name
            this.errorInfo = originalError.message
            this.stack_ = originalError.stack
        }
        Object.setPrototypeOf(this, IndexDBQueryError.prototype);
    }

    toString(){
        return {
            name: this.name,
            message: this.message,
            dbName: this.dbName,
            tableName: this.tableName,
            queryField: this.queryField,
            queryValue: this.queryValue,
            errorName: this.errorName,
            errorInfo: this.errorInfo,
            stack_: this.stack_
        };
    }
}